<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.Date"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>IPL 2012</title>
</head>
<body>
<%@ include file="global.jsp" %>
<%
Statement st = null; 
ResultSet rs = null; 
Connection con = null; 
PreparedStatement pstmt = null; 
String userName = (String) session.getAttribute("userName");
String league = (String) session.getAttribute("league");
String matchId = (String)session.getAttribute("matchId");
if(matchId!=null){
int SNo = 0;
int id = 0;
try{
	Class.forName(db_driver);
	con = DriverManager.getConnection(db_url, db_user, db_password);
     st=con.createStatement();
	 String str = "select count(*) from matchresults where MatchID = '"+matchId+"'";
	 rs=st.executeQuery(str);
	 while(rs.next()){
		 SNo = rs.getInt(1);
		 if(SNo>0){
		 	session.setAttribute("resposeText","Entry already made");
		 }
	 }
	 if(SNo==0){
		 String query = "insert into matchresults(matchId, winner, mom, sixes, sixesWinner)values(?,?,?,?,?)";
		 pstmt = con.prepareStatement(query); 
		 pstmt.setString(1, matchId);
		 pstmt.setString(2, request.getParameter("resultWinner"));
		 pstmt.setString(3, request.getParameter("resultMom"));
		 pstmt.setString(4, request.getParameter("resultSixes"));
		 pstmt.setString(5, request.getParameter("resultSixTeam"));
		 pstmt.executeUpdate();
		 pstmt.close();
		 session.setAttribute("resposeText","Succesfully Submited");
	 }
	 rs.close();
	 st.close();
}catch(Exception e){
	e.printStackTrace();
	session.setAttribute("resposeText",e.getMessage());
}finally{
	
}
}
response.sendRedirect("total.jsp");
%>

</body>
</html>